import vue from "../main";
export default {
  // 注册
  register(query = Object, callback = Function) {
    vue.$http
      .post("/account/register", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 登录
  login(query = Object, callback = Function) {
    vue.$http
      .post("/account/login", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 退出登录
  logout(callback = Function) {
    vue.$http
      .post("/account/logout")
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 修改密码
  changePassword(query = Object, callback = Function) {
    vue.$http
      .post("/account/changepassword", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 修改用户信息
  changeUserinfo(query = Object, callback = Function) {
    vue.$http
      .post("./account/changeuserinfo", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 上传头像
  uploadUserImage(query = Object, callback = Function) {
    vue.$http
      .post("/account/uploaduserimg", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 获取用户是否登录，并获取登录信息
  getUserinfoBySession(callback = Function) {
    vue.$http
      .get("/load/get/userinfo")
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 获取用户的头像昵称个性签名等
  getUserinfoByUsername(username = String, callback = Function) {
    vue.$http
      .get("/account/userimage", { params: { user: username } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 获取板块信息
  getSections() {
    vue.$http
      .get("/section/getsections")
      .then((res) => {
        if (res.data.status === 200) {
          vue.$store.state.pageControl.sectionlist = res.data.section;
        }
        vue.$store.state.pageControl.sectionLoadDone = true;
      })
      .catch((err) => {
        console.log(err);
      });
  },

  // 发布帖子
  releaseTopic(query = Object, callback = Function) {
    vue.$http
      .post("/topic/release", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 删除帖子
  deleteTopic(topic_id = Number, callback = Function) {
    vue.$http
      .get("/topic/delete", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 修改帖子
  modifyTopic(query = Object, callback = Function) {
    vue.$http
      .post("/topic/modify", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 获取帖子列表
  getTopicList(params = Object, callback = Function) {
    vue.$http
      .get("/topic/get", { params: params })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 获取帖子
  getTopic(topic_id = Number, callback = Function) {
    vue.$http
      .get("/topic/getTopic", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => console.log(err));
  },

  // 关注板块
  focusSection(section_id = Number, callback = Function) {
    vue.$http
      .get("/focus/add", { params: { section_id: section_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 取消关注板块
  cancelFocusSection(section_id = Number, callback = Function) {
    vue.$http
      .get("/focus/delete", { params: { section_id: section_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询关注了的板块
  focusedSections(callback = Function) {
    vue.$http
      .get("/focus/get")
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询是否关注了某板块
  isFocusedSection(section_id = Number, callback = Function) {
    vue.$http
      .get("/focus/isfocusd", { params: { section_id: section_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 点赞帖子
  likeTopic(topic_id = Number, callback = Function) {
    vue.$http
      .get("/liketopic/add", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 取消点赞帖子
  cancelLikeTopic(topic_id = Number, callback = Function) {
    vue.$http
      .get("/liketopic/delete", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询是否点赞了某帖子
  isLikeTopic(topic_id = Number, callback = Function) {
    vue.$http
      .get("/liketopic/islike", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 评论
  comment(query = Object, callback = Function) {
    vue.$http
      .post("/comment/add", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 删除评论
  deleteComment(comment_id = Number, callback = Function) {
    vue.$http
      .get("/comment/delete", { params: { comment_id: comment_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询帖子的评论列表
  getCommentListByTopic(topic_id = Number, callback = Function) {
    vue.$http
      .get("/comment/getbytopic", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询用户的评论列表
  getCommentListByUser(callback = Function) {
    vue.$http
      .get("/comment/getbyuser")
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 收藏帖子
  collectTopic(topic_id = Number, callback = Function) {
    vue.$http
      .get("/collect/add", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 取消收藏帖子
  cancelCollectTopic(topic_id = Number, callback = Function) {
    vue.$http
      .get("/collect/delete", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询是否收藏了某帖子
  isCollected(topic_id = Number, callback = Function) {
    vue.$http
      .get("/collect/iscollected", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询收藏列表
  getCollectionListByUser(callback = Function) {
    vue.$http
      .get("/collect/get")
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 添加浏览记录
  addViewRecord(topic_id = Number, callback = Function) {
    vue.$http
      .get("/viewrecord/add", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 删除某浏览记录
  deleteViewRecord(topic_id = Number, callback = Function) {
    vue.$http
      .get("/viewrecord/delete", { params: { topic_id: topic_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询用户的浏览记录
  getViewRecordList(callback = Function) {
    vue.$http
      .get("/viewrecord/get")
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 为评论点赞
  likeComment(comment_id = Number, callback = Function) {
    vue.$http
      .get("/likecomment/add", { params: { comment_id: comment_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 取消评论的点赞
  cancelLikeComment(comment_id = Number, callback = Function) {
    vue.$http
      .get("/likecomment/delete", { params: { comment_id: comment_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询是否为评论点赞了
  isLikeComment(comment_id = Number, callback = Function) {
    vue.$http
      .get("/likecomment/islike", { params: { comment_id: comment_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 添加好友
  addFriends(friendname = String, callback = Function) {
    vue.$http
      .get("/friend/add", { params: { friendname: friendname } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 删除好友
  deleteFriends(friendname = String, callback = Function) {
    vue.$http
      .get("/friend/delete", { params: { friendname: friendname } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询好友列表
  getFriendList(callback = Function) {
    vue.$http
      .get("/friend/getfriendlist")
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 查询聊天列表
  getMessageList(callback = Function) {
    vue.$http
      .get("/friend/getmessagelist")
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
  // 发送消息
  /**
   *
   * @param {Object} query 上传的参数，包含发送者的name，包含发送的消息
   * @param {Function} callback 回调函数
   */
  sendMessage(query = Object, callback = Function) {
    vue.$http
      .post("/message/send", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 删除消息记录
  /**
   *
   * @param {Number} message_id 消息id
   * @param {Function} callback
   */
  deleteMessage(message_id = Number, callback = Function) {
    vue.$http
      .get("/message/delete", { params: { message_id: message_id } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 查询聊天记录
  getMessageRecord(friendname = String, callback = Function) {
    vue.$http
      .get("/message/get", { params: { friendname: friendname } })
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 意见反馈
  giveAdvice(query = Object, callback = Function) {
    vue.$http
      .get("/advice", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 举报
  tipOff(query, callback = Function) {
    vue.$http
      .post("/tipoff", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },

  // 上传图片
  uploadImage(query = Object, callback = Function) {
    vue.$http
      .post("/upload/image", query)
      .then(callback)
      .catch((err) => {
        console.log(err);
      });
  },
};
